<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="名称" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-table
      v-loading="loading"
      :data="investorInclusionList"
      @selection-change="handleSelectionChange"
    >
      <!-- <el-table-column type="selection" width="55" align="center" /> -->

      <el-table-column label="LOGO" align="center" prop="logoUrl">
        <template v-slot:default="scope">
          <el-image
            style="width: 100px; height: 100px"
            :src="imageUrl + scope.row.logoUrl"
            fit="cover"
          ></el-image>
        </template>
      </el-table-column>
      <el-table-column label="名称" align="center" prop="name" />
      <el-table-column label="官网" align="center" prop="officialWebsite" />
      <!-- <el-table-column label="标签" align="center" prop="lable" /> -->
      <!-- <el-table-column label="介绍" align="center" prop="content" /> -->
      <el-table-column label="成立时间" align="center" prop="establishTime" />
      <el-table-column label="所在地" align="center" prop="location" />

      <el-table-column label="审核状态" align="center" prop="exStatus" />
      <!-- <el-table-column label="团队成员" align="center" prop="teamMember" /> -->
      <!-- <el-table-column label="语言类型" align="center" prop="lang" /> -->
      <!-- <el-table-column label="备注" align="center" prop="remark" /> -->
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-search"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['investorInclusion:investorInclusion:edit']"
            >查看</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改投资机构收录对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
      <el-form
        ref="form"
        :model="form"
        :rules="rules"
        label-width="100px"
        :disabled="true"
      >
        <el-form-item label="LOGO" prop="logoUrl">
          <el-image
            style="width: 100px; height: 100px"
            :src="imageUrl + form.logoUrl"
            fit="cover"
          ></el-image>
        </el-form-item>
        <el-form-item label="名称" prop="name">
          <el-input v-model="form.name" placeholder="请输入名称" />
        </el-form-item>
        <el-form-item label="官网" prop="officialWebsite">
          <el-input v-model="form.officialWebsite" type="textarea" />
        </el-form-item>
        <el-form-item label="标签" prop="lable">
          <el-input v-model="form.lable" type="textarea" />
        </el-form-item>
        <el-form-item label="介绍">
          <el-input :rows="10" v-model="form.officialWebsite" type="textarea" />
        </el-form-item>
        <el-form-item label="成立时间" prop="establishTime">
          <el-input v-model="form.establishTime" placeholder="请输入成立时间" />
        </el-form-item>
        <el-form-item label="所在地" prop="location">
          <el-input v-model="form.location" placeholder="请输入所在地" />
        </el-form-item>
        <!-- <el-form-item label="语言类型" prop="lang">
          <el-input v-model="form.lang" placeholder="请输入语言类型" />
        </el-form-item> -->
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" />
        </el-form-item>
        <el-form-item label="社媒链接" prop="smcList">
          <el-table :data="form.smcList" style="width: 100%">
            <el-table-column prop="webType" label="名称" width="180">
            </el-table-column>
            <el-table-column prop="webUrl" label="链接"> </el-table-column>
          </el-table>
        </el-form-item>
        <el-form-item label="团队成员" prop="workExperienceList">
          <el-table :data="form.workExperienceList" style="width: 100%">
            <el-table-column prop="name" label="名称" width="180">
            </el-table-column>
            <el-table-column prop="post" label="岗位" width="180">
            </el-table-column>
            <el-table-column prop="time" label="工作时间"> </el-table-column>
          </el-table>
        </el-form-item>

        <el-form-item label="关键事件" prop="eventList">
          <el-table :data="form.eventList" style="width: 100%">
            <el-table-column prop="event" label="名称" width="180">
            </el-table-column>
            <el-table-column prop="createTime" label="时间" width="180">
            </el-table-column>
            <el-table-column prop="link" label="链接"> </el-table-column>
          </el-table>
        </el-form-item>

        <el-form-item label="对外投资" prop="investDetailsList">
          <el-table :data="form.investDetailsList" style="width: 100%">
            <el-table-column prop="projectName" label="项目名" width="150">
            </el-table-column>
            <el-table-column prop="round" label="轮次" width="60">
            </el-table-column>
            <el-table-column prop="amount" label="金额" width="150">
            </el-table-column>
            <el-table-column prop="valuation" label="估值"> </el-table-column>
            <el-table-column prop="time" label="时间"> </el-table-column>
          </el-table>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listInvestorInclusion,
  getInvestorInclusion,
  delInvestorInclusion,
  addInvestorInclusion,
  updateInvestorInclusion,
  getExamineStatus,
} from "@/api/investorInclusion/investorInclusion";
import { imageUrl } from "@/config";
export default {
  name: "InvestorInclusion",
  data() {
    return {
      imageUrl,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 投资机构收录表格数据
      investorInclusionList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        mainId: null,
        logoUrl: null,
        name: null,
        officialWebsite: null,
        lable: null,
        content: null,
        establishTime: null,
        location: null,
        teamMember: null,
        lang: null,
      },
      // 表单参数
      form: {},
      status: "",
      // 表单校验
      rules: {},
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询投资机构收录列表 */
    getList() {
      this.loading = true;
      listInvestorInclusion(this.queryParams).then((response) => {
        this.investorInclusionList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    Formatter(row, column) {
      getExamineStatus(row.id).then((response) => {
        if (response.code == 200) {
          this.status = response.msg;
        } else {
          this.status = "";
        }
      });
      return this.status;
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        mainId: null,
        logoUrl: null,
        name: null,
        officialWebsite: null,
        lable: null,
        content: null,
        establishTime: null,
        location: null,
        teamMember: null,
        lang: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加投资机构收录";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getInvestorInclusion(id).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "查看投资机构收录";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {
            updateInvestorInclusion(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addInvestorInclusion(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm('是否确认删除投资机构收录编号为"' + ids + '"的数据项？')
        .then(function () {
          return delInvestorInclusion(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "investorInclusion/investorInclusion/export",
        {
          ...this.queryParams,
        },
        `investorInclusion_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>
